<?php

namespace app\selladmin\model;

use think\Model;
use think\Db;

/*
 * 用户
 */

class Custom extends Model {
    //用户对应的美容师
    public function Staff() {
        return $this->hasOne('Staff', 'id', 'staff_id')->field('id,staff_name,telephone');
    }

    //查询客户信息
    public function CustomInfo($custom_id,$store_id, $custom_name,$custom_phone, $pagenum) {
        if ($custom_id) {
            $customwhere['id'] = $custom_id;
        }
        if ($custom_name) {
            $customwhere['custom_name'] = $custom_name;
        }
        if ($custom_phone) {
            $customwhere['custom_phone'] = $custom_phone;
        }
        if ($store_id) {
            $customwhere['store_id'] = $store_id;
        }
        $customwhere['status'] = 2;
        $customwhere=  isset($customwhere)?$customwhere:[];
        $customList = Custom::with('Staff')
                ->where($customwhere)
                ->field("id,staff_id,custom_sex,custom_name,custom_photo,custom_phone,real_name,vip_status,service_count,visit_count,visit_time,update_time,add_time,store_id,consume_money,residue_ingt")
                ->order("login_time desc")
                ->paginate($pagenum, false, ['var_page' => 'page3', 'fragment' => 'custom'])
                ->appends(['store_id' => $store_id, 'id' => $store_id, 'custom_name' => $custom_name,'custom_phone'=>$custom_phone]);
        return $customList;
    }

}
